//
//  DWDatabaseModel.m
//  OCAPPDemo
//
//  Created by OS on 2022/10/18.
//

#import "DWFeedbackModel.h"

@implementation DWFeedbackModel
@synthesize images = _images;

- (instancetype)initWithContent:(NSString *)content
                    phoneNumber:(NSString *)phoneNumber
                       deviceID:(NSString *)deviceID
                      osVersion:(NSString *)osVersion
                      osChannel:(NSString *)osChannel
                            uid:(int)uid
                        childId:(int)childId {
    
    if (self = [super init]) {
        
        self.timestamp = [NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]];
        
        self.content = [NSString stringWithFormat:@"【家长端提交】%@", content];
        self.remark = content;
        self.phoneNumber = phoneNumber;
        
        self.cpuId = deviceID;
        self.emmcId = deviceID;
        self.androidId = deviceID;
        
        self.androidVersion = osVersion;
        self.cpbinfo = osVersion;
        self.channel = osChannel;
        self.osid = osChannel;
        
        self.userType = @"1";
        self.categoryId = @"7";
        self.root = @"1";
        self.brand = @"Apple";
        self.uiVersion = @"unknow";
        self.layoutName = @"用户反馈";
        self.uid = uid;
        self.childId = childId;
    }
    return self;
}

/**
 设置不需要存储的属性, 在模型.m文件中实现该函数.
 */
+(NSArray *)bg_ignoreKeys{
   return @[@"userId",@"appPkg",@"images"];
}

/**
 如果需要指定“唯一约束”字段, 在模型.m文件中实现该函数,这里指定 name和age 为“唯一约束”.
 */
+(NSArray *)bg_uniqueKeys{
    return @[@"timestamp"];
}

- (void)setImages:(NSArray<UIImage *> *)images {
    _images = images;
    
    NSMutableArray <NSData *>*datas = [[NSMutableArray alloc] init];
    for (UIImage *image in images) {
        NSData *data = UIImageJPEGRepresentation(image, 1);
        [datas addObject:data];
    }
    self.dataSoruces = [datas copy];
    
}

- (NSArray<UIImage *> *)images {
    NSMutableArray <UIImage *>*images = [[NSMutableArray alloc] init];
    for (NSData *data in self.dataSoruces) {
        UIImage *image = [UIImage imageWithData:data];
        [images addObject:image];
    }
    return [images copy];
}

@end
